//
//  UIButton+TYZAdd.m
//  VehicleInsuranceSupport
//
//  Created by TangBin on 2019/11/4.
//  Copyright © 2019 TangBin. All rights reserved.
//

#import "UIButton+TYZAdd.h"


@implementation UIButton (TYZAdd)

/**
 创建按钮
 
 @param superView 父视图
 @param frame frame
 @param font font description
 @param action action
 @param block block description
 @return return value description
 */
+ (UIButton *)createWithButton:(UIView *)superView frame:(CGRect)frame font:(UIFont *)font action:(SEL)action propertiesBlock:(void(^)(UIButton *button))block
{
    return [self createWithButton:superView frame:frame font:font target:superView action:action propertiesBlock:block];
//    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
//    btn.frame = frame;
//    [btn addTarget:superView action:action forControlEvents:UIControlEventTouchUpInside];
//    btn.titleLabel.font = font;
//    if (superView)
//    {
//        [superView addSubview:btn];
//    }
//
//    if (block)
//    {
//        block(btn);
//    }
//    return btn;
}

/// 创建按钮
/// @param superView 父视图
/// @param frame 大小位置
/// @param font 字的大小
/// @param target 目标 针对事件的
/// @param action 事件
/// @param block block description
+ (UIButton *)createWithButton:(UIView *)superView frame:(CGRect)frame font:(UIFont *)font target:(id)target action:(SEL)action propertiesBlock:(void (^)(UIButton * _Nonnull))block
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = frame;
    if (target)
    {
        [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    }
//    [btn addTarget:superView action:action forControlEvents:UIControlEventTouchUpInside];
    btn.titleLabel.font = font;
    if (superView)
    {
        [superView addSubview:btn];
    }
    
    if (block)
    {
        block(btn);
    }
    return btn;
}

@end
